//
//  DecorateSonHeaderView.m
//  PerfectWorld
//
//  Created by dllo on 16/8/31.
//  Copyright © 2016年 LST. All rights reserved.
//

#import "DecorateSonHeaderView.h"
#import "Masonry.h"
#import "SonModel.h"
#import "UIImageView+WebCache.h"
#import "SonUser.h"
#import "SonUserImage.h"
#import "TaskEnd.h"
#import "Space.h"
#import "Img.h"

@implementation DecorateSonHeaderView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self creatSubView:self.bounds];
    }
    return self;
}
- (void)creatSubView:(CGRect)sender {
    _backgroundImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height / 1.5)];
    [self addSubview:_backgroundImage];
    _labelName = [[UILabel alloc] init];
    _labelName.font = [UIFont systemFontOfSize:17];
    _labelName.textColor = [UIColor blackColor];
    _labelName.textAlignment = 1;
    [_backgroundImage addSubview:_labelName];
    _labelDown = [[UILabel alloc] init];
    _labelDown.numberOfLines = 1;
    _labelDown.textColor = [UIColor whiteColor];
    _labelDown.alpha = 0.3;
    _labelDown.textAlignment = 1;
    _labelDown.backgroundColor = [UIColor colorWithRed:0.27 green:0.24 blue:0.15 alpha:1.00];
    [_backgroundImage addSubview:_labelDown];
    _styleShow = [[UILabel alloc]init];
    _styleShow.textColor = [UIColor blackColor];
    [self addSubview:_styleShow];
    _areaShow = [[UILabel alloc] init];
    _areaShow.textColor = [UIColor blackColor];
    [self addSubview:_areaShow];
    _typeShow = [[UILabel alloc] init];
    _typeShow.textColor = [UIColor blackColor];
    [self addSubview:_typeShow];
    _costShow = [[UILabel alloc] init];
    _costShow.textColor = [UIColor blackColor];
    [self addSubview:_costShow];
}
- (void)layoutSubviews {
    [super layoutSubviews];
    _nameImageView = [[UIImageView alloc]init];
    _nameImageView.layer.cornerRadius = 40;
    _nameImageView.layer.masksToBounds = YES;
    [_backgroundImage addSubview:_nameImageView];
    [_nameImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(80);
        make.centerX.mas_equalTo(0);
        make.centerY.mas_equalTo(0);
    }];
    [_labelName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(_nameImageView);
        make.height.mas_equalTo(30);
        make.centerX.mas_equalTo(_nameImageView);
        make.top.mas_equalTo(_nameImageView.mas_bottom).mas_offset(10);
    }];
    [_labelDown mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(_backgroundImage);
        make.height.mas_equalTo(30);
        make.bottom.mas_equalTo(_backgroundImage.mas_bottom);
    }];
    [_styleShow mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo (_backgroundImage.mas_bottom).mas_offset(10);
        make.width.mas_equalTo (self.frame.size.width / 3);
        make.height.mas_equalTo (30);
        make.left.mas_equalTo(30);
    }];
    [_areaShow mas_makeConstraints:^(MASConstraintMaker *make) {
         make.right.mas_equalTo (30);
        make.top.width.height.mas_equalTo(_styleShow);
    }];
    [_typeShow mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.left.mas_equalTo (_styleShow);
        make.bottom.mas_equalTo (0);
    }];
    [_costShow mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.right.mas_equalTo (_areaShow);
        make.bottom.mas_equalTo (_typeShow);
    }];
}

- (void)setSonModel:(SonModel *)sonModel {
    _sonModel = sonModel;
    [_nameImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", _sonModel.user.userImage.large]] placeholderImage:nil];
    _labelDown.text = sonModel.title;
    _labelName.text = sonModel.user.userName;
    _styleShow.text = [NSString stringWithFormat:@"风格:   %@",sonModel.styleShow];
    _areaShow.text = [NSString stringWithFormat:@"面积:   %@", sonModel.areaShow];
    _costShow.text = [NSString stringWithFormat:@"户型:   %@", sonModel.costShow];
    _typeShow.text = [NSString stringWithFormat:@"预算:   %@",sonModel.typeShow];
    NSNumber *num = sonModel.coverPhoto;
    NSString *str = [num description];
    NSString *str1 = [str substringToIndex:3];
    [_backgroundImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://image.gooju.cn/images/%@/9/%@_0_9-.jpg", str1, str]]];placeholderImage:nil;
}


@end
